<?php
require_once 'menu_item_model.php';
class Menu_model extends MY_Model {
    var $table_name = 'menu';
    var $primary_key = 'id';
    function insert($data)
    {
    	try{
	        $this->filterData($data);
	        $this->db->insert($this->table_name, $data);
	        $menu_id = $this->db->insert_id()  ;
	        $menuitem_data = array(
	            'title' => 'root',
	            'lft' => 1,
	            'rgt' => 2,
	            'menu_id' => $menu_id
	        );
	        $this->db->insert('menu_item', $menuitem_data);
	        return $menu_id;
    	} catch(Exception $e){
	    	return false;   
    	}
    }
    function  delete($id) {
    	$menu_item_model = new Menu_item_model();
    	return (parent::delete($id)&&$menu_item_model->delete_by_field(array('menu_id' => $id)));	
    }
}  
     ?>